import smtplib
from email.mime.text import MIMEText
from email.header import Header

mail_host = 'smtp.qq.com'   # 中转服务器
mail_user = '2429160671@qq.com' #使用者
mail_pass = 'xzfwjkhtpsrydjdh'#密码

sender = '2429160671@qq.com'       # 发送方
receivers = ['2429160671@qq.com']       # 接收方

message = MIMEText('python 测试', 'plain', 'utf-8')#创建待发送的信息
message['From'] = Header("ennio", 'utf-8')
message['To'] = Header("测试", 'utf-8')

subject = 'python smtp 测试'
message['Subject'] = Header(subject, 'utf-8')

try:
    smtpObj = smtplib.SMTP() #创建套接字
    smtpObj.connect(mail_host, 25)  # 建立连接
    smtpObj.login(mail_user, mail_pass) # 登陆授权
    smtpObj.sendmail(sender, receivers, message.as_string())  # 发送邮件
    print("Success")
    smtpObj.close()
except smtplib.SMTPException:
    print("Error")